<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>标签管理</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="apple-mobile-web-app-status-bar-style" content="black">
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="format-detection" content="telephone=no">
	<link rel="stylesheet" href="${s.base}/js/layui/css/layui.css" media="all" />
	<link rel="stylesheet" href="${s.base}/css/base/base.css" media="all" />
</head>
<body class="childrenBody">
<form class="layui-form">
	<blockquote class="layui-elem-quote quoteBox">
		<form class="layui-form">
			<div class="layui-inline">
				<label class="layui-input-inline">名称：</label>
				<div class="layui-input-inline">
					<input type="text" class="layui-input" id="name" placeholder="请输入名称" />
				</div>
				<label class="layui-input-inline">类型：</label>
				<div class="layui-input-inline">
					<select class="layui-select" id="type">
						<option value="">全部</option>
						<option value="1" >想要</option>
						<option value="2" >我的标签</option>
						<option value="3" >可聊话题</option>
						<option value="4" >运动偏好</option>
						<option value="5" >音乐偏好</option>
					</select>
				</div>

				<div class="layui-inline">
					<a class="layui-btn search_btn" data-type="reload">搜索</a>
					<a class="layui-btn layui-btn-normal add_btn">添加</a>
				</div>
			</div>
		</form>
	</blockquote>
	<table id="entityList" lay-filter="entityList"></table>
</form>



<script type="text/javascript" src="${s.base}/js/layui/layui.js"></script>
<script type="text/javascript" src="${s.base}/js/compont.js"></script>
<script type="text/javascript">
    layui.use(['form','layer','laydate','table','laytpl'],function(){
        var form = layui.form,
            layer = parent.layer === undefined ? layui.layer : top.layer,
            $ = layui.jquery,
            laydate = layui.laydate,
            laytpl = layui.laytpl,
            table = layui.table;

        //列表
        var tableIns = table.render({
            elem: '#entityList',
            url : '/dict/jsonList',
            cellMinWidth : 95,
            page : true,
            height : "full-125",
            limit : 20,
            method:'post',
            limits : [10,15,20,25],
            id : "entityList",
            cols : [[
                {type: 'numbers', title: '序号'},
                {field: 'name', title: '名称',align:'center'},
                {field: 'type', title: '类型',align:'center', templet:function(d){
                	if(d.type=="1"){
                	    return "想要";
					}else if(d.type=="2"){
                        return "我的标签";
                    } else if(d.type=="3"){
                        return "可聊话题";
                    }else if(d.type=="4"){
                        return "运动偏好";
                    }else if(d.type=="5"){
                        return "音乐偏好";
                    }else{
                        return "无";
                    }
                }},
                {field: 'sort', title: '排序',align:'center'},
                {field: 'createTime', title: '创建时间', align:'center', templet:function(d){
                    return timeStamp2String(d.createTime);
                }, sort: true},
                {title: '操作',width:170,align:"center", templet:function (d) {
                    return '<a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>'+
                        '<a class="layui-btn layui-btn-xs" lay-event="del">删除</a>';
                }}
            ]]
        });

        //搜索
        $(".search_btn").on("click",function(){
            table.reload("entityList",{
                page: {
                    curr: 1 //重新从第 1 页开始
                },
                where: {
                    name: $("#name").val(),
                    type: $("#type").val()
                }
            })
        });

        //增加/编辑
        function addEntity(params){
            var title="编辑";
            if(params==null||params==""){
                title="添加"
            }
            var index = layui.layer.open({
                title :title,
                type : 2,
                content : "/dict/selectEntity"+params,
                success : function(layero, index){
                    var body = layui.layer.getChildFrame('body', index);
                    body.find(".closeLay").bind("click",function () {
                        layui.layer.close(index);
                    })
                    layui.layer.full(index);
                }
            });
        }
        $(".add_btn").click(function(){
            addEntity('');
        })

        //列表操作
        table.on('tool(entityList)', function(obj){
            var layEvent = obj.event,
                data = obj.data;
            if(layEvent === 'edit'){ //编辑
                addEntity("?id="+data.id);
            }else if(layEvent === 'del'){ //删除
                layer.confirm('是否删除【'+data.name+'】？',{icon:3, title:'提示信息'},function(index){
                    $.get("/dict/deleteEntity",{
                        "id":data.id,
                        "_method":"DELETE"
                    },function(result){
                        if(1==result.returnInfo.state){
                            tableIns.reload();
                            layer.close(index);
                        }else{
                            top.layer.msg(result.returnInfo.errorMsg);
                        }
                    })
                });
            }
        });

    })
</script>
</body>
</html>